package com.example.wxy.bbtapp.Models.RetrunValue;

import com.google.gson.Gson;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by yons on 2017/9/9.
 */

public class ResultData<T> implements Serializable {

    public boolean isSuccess() {
        return IsSuccess;
    }

    public void setSuccess(boolean success) {
        IsSuccess = success;
    }

    public Object getMessage() {
        return Message;
    }

    public void setMessage(Object message) {
        Message = message;
    }

    public int getDataCount() {
        return DataCount;
    }

    public void setDataCount(int dataCount) {
        DataCount = dataCount;
    }

    public T getData() {
        return Data;
    }

    public void setData(T data) {
        Data = data;
    }

    private boolean IsSuccess;
    private Object Message;
    private int DataCount;
    private T Data;

    public static ResultData fromJson(String json, Class clazz) {
        Gson gson = new Gson();
        Type objectType = type(ResultData.class, clazz);
        return gson.fromJson(json, objectType);
    }

    static ParameterizedType type(final Class raw, final Type... args) {
        return new ParameterizedType() {
            public Type getRawType() {
                return raw;
            }

            public Type[] getActualTypeArguments() {
                return args;
            }

            public Type getOwnerType() {
                return null;
            }
        };
    }

}
